package com.lmm.yydshtester.config;

import com.lmm.yydshtester.util.SpringContextUtil;
import com.lmm.yydshtester.zk.CuratorZKClient;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @title: ZkClientConfig
 * @Description: zk客户端配置类
 * @Author Lmm
 * @Date: 2022/11/10 19:16
 * @Version 1.0
 */
@Configuration
public class ZkClientConfig implements ApplicationContextAware {
    @Value("${zookeeper.connect.url}")
    private String zkConnect;

    @Value("${zookeeper.connect.SessionTimeout}")
    private String zkSessionTimeout;


    /**
     * @see BeanInitializationException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
    {
        SpringContextUtil.setContext(applicationContext);

    }


    @Bean(name = "curatorZKClient")
    public CuratorZKClient curatorZKClient()
    {
        return new CuratorZKClient(zkConnect, zkSessionTimeout);
    }
}
